﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<form id="form1" enctype="multipart/form-data">
    <div class="widget-body">
        <div id="wizard" class="wizard" data-target="#wizard-steps" style="border-left: none; border-top: none; border-right: none;">
            <ul class="steps">
                <li data-target="#step-1" class="active"><span class="step">1</span>人员信息<span class="chevron"></span></li>
                <li data-target="#step-2"><span class="step">2</span>关联岗位<span class="chevron"></span></li>
            </ul>
        </div>
        <div class="step-content" id="wizard-steps" style="border-left: none; border-bottom: none; border-right: none;">
            <div class="step-pane active" id="step-1" style="margin: 18px; margin-bottom: 0px;">
                <div class="panel panel-default">
                    <div class="panel-body" style="width: 98%; margin-left: -34px;">
                        <table class="form">
                            <tr>
                                <th class="formTitle"><span class="required">*</span>组织机构：</th>
                                <td class="formValue formDdlSelectorTd">
                                    <select id="OrganizeId" name="OrganizeId" class="form-control required">
                                        <option value="">==请选择==</option>
                                    </select>
                                </td>
                                <th class="formTitle">科室：</th>
                                <td class="formValue formDdlSelectorTd">
                                    <select id="DepartmentCode" name="DepartmentCode" class="form-control">
                                        <option value="">==请选择==</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle"><span class="required">*</span>姓名：</th>
                                <td class="formValue">
                                    <input id="Name" name="Name" type="text" class="form-control required" placeholder="请输入姓名" />
                                </td>
                                <th class="formTitle">性别：</th>
                                <td class="formValue formDdlSelectorTd">
                                    <select id="Gender" name="Gender" class="form-control required">
                                        <option value="true">男</option>
                                        <option value="false">女</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle"><span class="required">*</span>工号：</th>
                                <td class="formValue">
                                    <input id="gh" name="gh" type="text" class="form-control required" placeholder="请输入工号" />
                                </td>
                                <th class="formTitle">康复类别：</th>
                                <td class="formValue formDdlSelectorTd">
                                    <select id="kflb" name="kflb" class="form-control">
                                        <option value="">==请选择==</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle"><span class="required">*</span>证件类别：</th>
                                <td class="formValue formDdlSelectorTd">
                                    @Html.DropDownList("zjlx", Newtouch.Infrastructure.EnumZjlx.Sfz.ToDescSelectList(), "==请选择==", new { @class = "form-control required" })
                                </td>
                                <th class="formTitle">证件号：</th>
                                <td class="formValue">
                                    <input id="zjh" name="zjh" type="text" class="form-control" placeholder="请输入证件号" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">职称：</th>
                                <td class="formValue formDdlSelectorTd">
                                    <select id="zc" name="zc" class="form-control ">
                                        <option value="">==请选择==</option>
                                    </select>
                                </td>
                                <th class="formTitle">头像：</th>
                                <td class="formValue">
                                    <input id="HeadIcon" name="HeadIcon" type="text" class="form-control" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">手机：</th>
                                <td class="formValue">
                                    <input id="MobilePhone" name="MobilePhone" type="text" class="form-control" />
                                </td>
                                <th class="formTitle">生日：</th>
                                <td class="formValue">
                                    <input id="Birthday" name="Birthday" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">微信：</th>
                                <td class="formValue">
                                    <input id="WeChat" name="WeChat" type="text" class="form-control" />
                                </td>
                                <th class="formTitle">邮箱：</th>
                                <td class="formValue">
                                    <input id="Email" name="Email" type="text" class="form-control" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle"><span class="required">*</span>首拼：</th>
                                <td class="formValue">
                                    <input id="py" type="text" class="form-control required" placeholder="" />
                                </td>

                                <th class="formTitle">模板权限：</th>
                                <td class="formValue formDdlSelectorTd">
                                    @Html.DropDownList("mbqx", Newtouch.Infrastructure.EnumTcfw.Person.ToDescSelectList(), "==请选择==", new { @class = "form-control" })
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">排序：</th>
                                <td class="formValue">
                                    <input id="px" name="px" type="text" class="form-control" placeholder="" />
                                </td>
                                <th class="formTitle" style="height: 35px;">选项：</th>
                                <td class="formValue" style="padding-top: 1px;">
                                    <div class="ckbox">
                                        <input id="zt" name="zt" type="checkbox" checked="checked"><label for="zt">有效</label>
                                    </div>
                                    <div class="ckbox" id="divCreateAsLoginUser">
                                        <input id="asLoginUser" name="asLoginUser" type="checkbox" checked="checked"><label for="asLoginUser">作为登录用户</label>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">电子签名(jpg/png)：</th>
                                <td class="formValue">
                                    <input id="dzqmUpload" name="dzqmUpload" type="file" class="form-control" />
                                </td>
                                <th class="formTitle">签名预览：</th>
                                <td class="formValue">
                                    <img id="dzqmImage" name="dzqmImage" class="form-control" style="height: 40px; width:auto" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">国家医师代码：</th>
                                <td class="formValue">
                                    <input id="gjybdm" name="gjybdm" type="text" class="form-control" />
                                </td>
                                <th class="formTitle">BI邮箱：</th>
                                <td class="formValue">
                                    <input id="MsEmail" name="MsEmail" type="text" class="form-control" />
                                </td>
                            </tr>
							<tr>
								<th class="formTitle">医师职业证书编码：</th>
								<td class="formValue">
									<input id="yszydm" name="yszydm" type="text" class="form-control" />
								</td>
							</tr>
                            <tr>
                                <th class="formTitle" valign="top" style="padding-top: 1px;">
                                    备注：
                                </th>
                                <td class="formValue" colspan="3">
                                    <textarea id="Description" name="Description" class="form-control" style="height: 20px;"></textarea>
                                </td>
                            </tr>

                        </table>
                    </div>
                </div>
            </div>
            <div class="step-pane" id="step-2">
                <div>
                    <div id="dutyList"></div>
                </div>
            </div>
        </div>
        <div class="form-button" id="wizard-actions" style="height:30px;bottom:auto;margin-top:auto">
            <a id="btn_last" disabled class="btn btn-default btn-prev">上一步</a>
            <a id="btn_next" class="btn btn-default btn-next" style="margin-right: 10px;">下一步</a>
            <a id="btn_finish" class="btn btn-default" style="display: none;margin-right: 10px;" onclick="submitForm()">完成</a>
        </div>
    </div>
</form>

<script>
    var keyValue = $.request("keyValue");
    $(function () {
        initControl();
        if (!!keyValue) {
            $("#divCreateAsLoginUser").hide();
            $.najax({
                url: "/Staff/GetFormJson",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#form1").formSerialize(data);

                    $("#OrganizeId").prop("disabled", true);
                    $.ajax({
                        url: "/Staff/GetFormPicture",
                        type: "get",
                        cache: false,
                        data: { keyValue: keyValue, orgId: data.OrganizeId },
                        dataType: "text",
                        success: function (data) {
                            if (data)
                            {
                                $("#dzqmImage").attr('src', data);
                            }

                        },
                        error: function (ds) {

                        }
                    });
                }
            });
        }
        else {
            var newOrgId = $.request('orgId');
            if (newOrgId) {
                $("#OrganizeId").val(newOrgId).trigger('change');
            }
        }
    });
    function initControl() {
        $("#Gender").bindSelect();
        $('#mbqx').bindSelect();
        //组织机构下拉框
        $("#OrganizeId").bindSelect({
            url: "/Organize/GetChildTreeSelectJson",
        });
        //组织对应的科室下拉框加载
        $("#OrganizeId").bind("change", function () {
            var organizeId = $(this).val();
            $("#DepartmentCode").bindSelect({
                url: "/Department/GetTreeSelectJson?organizeId=" + organizeId,
            });
            //加载职称
            $("#zc").bindSelect({
                url: "/ItemsData/GetSelectJson",
                param: { code: "DoctorTitle", OrganizeId: organizeId }
            });
            //加载康复类别
            $("#kflb").bindSelect({
                url: "/ItemsData/GetSelectJson",
                param: { code: "RehabTreatmentMethod", OrganizeId: organizeId }
            });
        });

        
        //首拼
        $('#Name').keyup(function () {
            $('#py').val($(this).toShouPin());
        });
        zjlx: $("#zjlx").val(),
            $('#wizard').wizard().on('change', function (e, data) {
                debugger
            var $finish = $("#btn_finish");
            var $next = $("#btn_next");
            var MsEmail = $("#MsEmail").val()
            var zjh = $("#zjh").val()
            //var checkzjh = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
            //if (!checkzjh.test(zjh)) {
            //    $.modalAlert("请输入正确的身份证号码", 'warning');
            //    return false;
            //}
            //var num = 0;
            //if (MsEmail=='') {
            //    $.modalAlert("BI邮箱为必填项", 'warning');
            //    return false;
            //}
            //$.ajax({
            //    type: "POST",
            //    url: "/Staff/checkEamil",
            //    data: { MsEmail: MsEmail },
            //    dataType: "json",
            //    async: false,
            //    success: function (data) {
            //         num = data
            //    },
            //});

            //if (num!=1) {
            //    $.modalAlert("BI邮箱格式不准确", 'warning');
            //    return false;
            //}
          
            if (data.direction == "next") {
                switch (data.step) {
                    case 1:
                        if (!$('#form1').formValid()) {

                            return false;
                        }
                        if (zjlx.value != 1) {
                            $.modalAlert("请选择证件类型", 'warning');
                            return false;
                        }
                        $finish.show();
                        $next.hide();
                        break;
                    default:
                        break;
                }
            } else {
                $finish.hide();
                $next.show();
            }
             
        });
        
        //init duty tree
        $("#dutyList").treeview({
            height: 400,
            slimscroll: false,
            showcheck: true,
            url: "/Duty/GetDutyList",
            param: { staffId: keyValue } 
        });
    }
    var imgReaderI = new FileReader();
    var regexImageFilter = /^(?:image\/bmp|image\/png|image\/jpeg|image\/jpg)$/i;
    
    
    

    imgReaderI.onload = function (evt) {
        
        //将数据结果赋值给image的src
        $("#dzqmImage").attr('src', evt.target.result);
    }
    $("#dzqmUpload").change(function () {
        var imgfFile = $("#dzqmUpload").prop('files')[0];
        if (!regexImageFilter.test(imgfFile.type)) {
            $.modalAlert("仅支持Jpg,Png格式的图片", 'warning');
            return;
        }
        if (imgfFile.size > (10 * 1024)) {
            $.modalAlert("上传图片不能超过10kb", 'warning');
            return;
        }
        imgReaderI.readAsDataURL(imgfFile);
    });

    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        var postData = $("#form1").formSerialize();
        postData["dutyList"] = String($("#dutyList").getCheckedNodes());

        var formData = new FormData();
        formData.append("file", $("#dzqmUpload")[0].files[0]);
        var Picture = $('#form1 [name="dzqmUpload"]').prop('files');//照片

        $.submitForm({
            url: "/Staff/SubmitForm?keyValue=" + keyValue,
            param: postData,
            success: function (refdata) {
                $.ajax({
                    url: "/Staff/FileUpLoad?staffId=" + refdata.data + '&orgId=' + postData.OrganizeId,
                    type: 'POST',
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (data) {
                    },
                    error: function (responseStr) {
                    }
                });
                $.currentWindow().$("#gridList").resetSelection();
                $.currentWindow().$("#gridList").trigger("reloadGrid");

            }
        })
    }

    $('#zjh').bind("blur",
        function (e) {
            if ((e.keyCode === 13 || e.type === "blur") && $('#zjlx').val() === "1") {
                //获取输入的身份证号
                var sfzh = $(this).val();
                var len = $(this).val().length;
                //if (len == 18 || len == 15) {//checkCard()
                if (len === 18 || len === 15) {
                    var csrq;
                    csrq = sfzh.substr(6, 8);
                    if ((len === 15 && csrq) || len === 18) {
                        csrq = csrq.replace(/(.{4})(.{2})/, "$1-$2-");
                        //获取性别
                        var xb;
                        if (parseInt(sfzh.charAt(16) / 2) * 2 != sfzh.charAt(16))
                            xb = "true";
                        else
                            xb = "false";
                        //$('#zjh').val(sfzh);
                        $('#Birthday').val($('#Birthday').attr('data-dateFmt') == 'yyyy-MM-dd' ? $.getDate({ date: csrq }) : $.getTime({ date: csrq }));
                        var objSelect = document.getElementsByName('Gender');
                        for (var i = 0; i < objSelect[0].length; i++) {
                            if (objSelect[0].options[i].value == xb) {
                                objSelect[0].options[i].selected = true;
                                break;
                            }
                        }
                        var myvalue;
                        $('#select2-Gender-container').each(function () {
                            myvalue= xb=='true'?'男':'女';
                            $(this).html(myvalue);
                        });
                        $('#select2-Gender-container').attr('title', myvalue);
                    }
                }
            }
        });
</script>